package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.base.ResultModel
import com.asia5b.a5mall.middleware.model.member.CouponModel
import io.reactivex.functions.Consumer

class CouponListFragmentVM : SimpleViewModel() {
   private var page = 1
   private var sumPage = 1000


    /**
     * @Note   加载优惠券
     * @param  page  分页
     * @param  state 状态 1：未使用,2:已使用,3:已过期
     */
    fun getDatas(refresh: Int, state: Int) {
        if (refresh <= 1) {
            page = 1
            sumPage = 1000
        }
        if (page > sumPage) {
//            loadMvpView.dismissLoadingBar()

            return
        }

        val observable = memberApi.getCouponListByAll(state, page)

        baseSubscribe(observable, SimpleNetParams(isShowLoading = (refresh == 0)), Consumer { resultModel ->
            sumPage = resultModel.sumPage
            page=resultModel.page+1
//            providerView().getDatasResult(resultModel.data)
            getDatasResultLiveData.value=resultModel
        })
    }
    val getDatasResultLiveData=MutableLiveData<ResultModel<ArrayList<CouponModel>>>()
}